/**
 * @author chenlei
 * @date 2019-11-23
 * @description
 */
package com.example.demospringboot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demospringboot.entity.OrderResponse;
import com.example.demospringboot.entity.TicketRequest;
import com.example.demospringboot.entity.TicketResponse;
import com.example.demospringboot.entity.User;
import com.example.demospringboot.netty.http.service.HttpService;
import com.example.demospringboot.service.IUserService;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.*;
import io.netty.util.CharsetUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenlei
 * @date 2019-11-23
 * @description
 */
@RestController
@RequestMapping("/user")
@Api(tags = "ddd")
public class UserController {

    @Autowired
    private IUserService userService;
    @Autowired
    private HttpService httpService;

    @ApiOperation("dfa")
    @PostMapping("/queryList")
    public Object queryList(@RequestBody User user) {
        return userService.queryList(new Page<>(1, 10), user);
    }

    @GetMapping("/add")
    public Object add(@Validated User user) throws Exception {
        String msg = "<html><head><title>test</title></head><body>hello,world</body></html>";
        FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,HttpMethod.GET,"/user/add",Unpooled.copiedBuffer("i am coming",CharsetUtil.UTF_8));
        FullHttpResponse result = httpService.send(request);
        return result.content().toString(CharsetUtil.UTF_8);
    }

    @PostMapping(value = "/test", consumes = {MediaType.APPLICATION_XML_VALUE}, produces = MediaType.APPLICATION_XML_VALUE)
    public TicketResponse test(@RequestBody TicketRequest ticketRequest) {
        TicketResponse ticketResponse = new TicketResponse();
        List<OrderResponse> orders = new ArrayList<OrderResponse>();
        OrderResponse o = new OrderResponse();
        o.setMsg("投注成功");
        orders.add(o);
        ticketResponse.setOrderList(orders);
        return ticketResponse;
    }

}
